
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 06/26/2012 16:24:36
-- Generated from EDMX file: D:\Bruno\Facultad\9no Semestre\TSI1\Laboratorio\IndignadoFramework\IndignadoFramework.DataAccessLayer\EntityModels\IndignadoModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [IndignadoFramework];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_MovimientoConvocatoria]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Convocatorias] DROP CONSTRAINT [FK_MovimientoConvocatoria];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioConvocatoria_Usuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UsuarioConvocatoria] DROP CONSTRAINT [FK_UsuarioConvocatoria_Usuario];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioConvocatoria_Convocatoria]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UsuarioConvocatoria] DROP CONSTRAINT [FK_UsuarioConvocatoria_Convocatoria];
GO
IF OBJECT_ID(N'[dbo].[FK_NotificacionConvocatoria]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Notificaciones] DROP CONSTRAINT [FK_NotificacionConvocatoria];
GO
IF OBJECT_ID(N'[dbo].[FK_NotificacionUsuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Notificaciones] DROP CONSTRAINT [FK_NotificacionUsuario];
GO
IF OBJECT_ID(N'[dbo].[FK_NotificacionMovimiento]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Notificaciones] DROP CONSTRAINT [FK_NotificacionMovimiento];
GO
IF OBJECT_ID(N'[dbo].[FK_MovimientoUsuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Usuarios] DROP CONSTRAINT [FK_MovimientoUsuario];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioContenido]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Contenidos] DROP CONSTRAINT [FK_UsuarioContenido];
GO
IF OBJECT_ID(N'[dbo].[FK_ContenidoMovimiento]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Contenidos] DROP CONSTRAINT [FK_ContenidoMovimiento];
GO
IF OBJECT_ID(N'[dbo].[FK_MarcaMovimiento]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Marcas] DROP CONSTRAINT [FK_MarcaMovimiento];
GO
IF OBJECT_ID(N'[dbo].[FK_MarcaUsuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Marcas] DROP CONSTRAINT [FK_MarcaUsuario];
GO
IF OBJECT_ID(N'[dbo].[FK_MarcaContenido]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Marcas] DROP CONSTRAINT [FK_MarcaContenido];
GO
IF OBJECT_ID(N'[dbo].[FK_OrigenDeDatoMovimiento]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrigenDeDatos] DROP CONSTRAINT [FK_OrigenDeDatoMovimiento];
GO
IF OBJECT_ID(N'[dbo].[FK_OrigenDeDatoFiltro]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Filtros] DROP CONSTRAINT [FK_OrigenDeDatoFiltro];
GO
IF OBJECT_ID(N'[dbo].[FK_FiltroMovimiento]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Filtros] DROP CONSTRAINT [FK_FiltroMovimiento];
GO
IF OBJECT_ID(N'[dbo].[FK_MovimientoGaleria]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Galerias] DROP CONSTRAINT [FK_MovimientoGaleria];
GO
IF OBJECT_ID(N'[dbo].[FK_MovimientoChat]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Chat] DROP CONSTRAINT [FK_MovimientoChat];
GO
IF OBJECT_ID(N'[dbo].[FK_SesionChatMensaje]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Mensajes] DROP CONSTRAINT [FK_SesionChatMensaje];
GO
IF OBJECT_ID(N'[dbo].[FK_MovimientoMensaje]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Mensajes] DROP CONSTRAINT [FK_MovimientoMensaje];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioSesionChat]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Chat] DROP CONSTRAINT [FK_UsuarioSesionChat];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioSesionChat1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Chat] DROP CONSTRAINT [FK_UsuarioSesionChat1];
GO
IF OBJECT_ID(N'[dbo].[FK_CategoriaTematicaMovimiento]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CategoriasTematicas] DROP CONSTRAINT [FK_CategoriaTematicaMovimiento];
GO
IF OBJECT_ID(N'[dbo].[FK_CategoriaTematicaUsuario_CategoriaTematica]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CategoriaTematicaUsuario] DROP CONSTRAINT [FK_CategoriaTematicaUsuario_CategoriaTematica];
GO
IF OBJECT_ID(N'[dbo].[FK_CategoriaTematicaUsuario_Usuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CategoriaTematicaUsuario] DROP CONSTRAINT [FK_CategoriaTematicaUsuario_Usuario];
GO
IF OBJECT_ID(N'[dbo].[FK_CategoriaTematicaConvocatoria]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Convocatorias] DROP CONSTRAINT [FK_CategoriaTematicaConvocatoria];
GO
IF OBJECT_ID(N'[dbo].[FK_MeGusta_inherits_Marca]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Marcas_MeGusta] DROP CONSTRAINT [FK_MeGusta_inherits_Marca];
GO
IF OBJECT_ID(N'[dbo].[FK_Inadecuado_inherits_Marca]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Marcas_Inadecuado] DROP CONSTRAINT [FK_Inadecuado_inherits_Marca];
GO
IF OBJECT_ID(N'[dbo].[FK_Video_inherits_Contenido]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Contenidos_Video] DROP CONSTRAINT [FK_Video_inherits_Contenido];
GO
IF OBJECT_ID(N'[dbo].[FK_Imagen_inherits_Contenido]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Contenidos_Imagen] DROP CONSTRAINT [FK_Imagen_inherits_Contenido];
GO
IF OBJECT_ID(N'[dbo].[FK_Link_inherits_Contenido]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Contenidos_Link] DROP CONSTRAINT [FK_Link_inherits_Contenido];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Contenidos]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Contenidos];
GO
IF OBJECT_ID(N'[dbo].[Convocatorias]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Convocatorias];
GO
IF OBJECT_ID(N'[dbo].[Filtros]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Filtros];
GO
IF OBJECT_ID(N'[dbo].[Movimientos]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Movimientos];
GO
IF OBJECT_ID(N'[dbo].[Notificaciones]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Notificaciones];
GO
IF OBJECT_ID(N'[dbo].[OrigenDeDatos]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrigenDeDatos];
GO
IF OBJECT_ID(N'[dbo].[UsuariosAdmin]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UsuariosAdmin];
GO
IF OBJECT_ID(N'[dbo].[Usuarios]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Usuarios];
GO
IF OBJECT_ID(N'[dbo].[Galerias]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Galerias];
GO
IF OBJECT_ID(N'[dbo].[Marcas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Marcas];
GO
IF OBJECT_ID(N'[dbo].[Chat]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Chat];
GO
IF OBJECT_ID(N'[dbo].[Mensajes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Mensajes];
GO
IF OBJECT_ID(N'[dbo].[CategoriasTematicas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CategoriasTematicas];
GO
IF OBJECT_ID(N'[dbo].[Marcas_MeGusta]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Marcas_MeGusta];
GO
IF OBJECT_ID(N'[dbo].[Marcas_Inadecuado]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Marcas_Inadecuado];
GO
IF OBJECT_ID(N'[dbo].[Contenidos_Video]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Contenidos_Video];
GO
IF OBJECT_ID(N'[dbo].[Contenidos_Imagen]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Contenidos_Imagen];
GO
IF OBJECT_ID(N'[dbo].[Contenidos_Link]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Contenidos_Link];
GO
IF OBJECT_ID(N'[dbo].[UsuarioConvocatoria]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UsuarioConvocatoria];
GO
IF OBJECT_ID(N'[dbo].[CategoriaTematicaUsuario]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CategoriaTematicaUsuario];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Contenidos'
CREATE TABLE [dbo].[Contenidos] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [ContenidoFechaCreacion] datetime  NOT NULL,
    [ContenidoDadoBaja] bit  NOT NULL,
    [UsuarioId] int  NOT NULL,
    [MovimientoId] int  NOT NULL
);
GO

-- Creating table 'Convocatorias'
CREATE TABLE [dbo].[Convocatorias] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [ConvocatoriaTitulo] nvarchar(max)  NOT NULL,
    [ConvocatoriaFechaInicio] datetime  NOT NULL,
    [ConvocatoriaFechaFin] datetime  NOT NULL,
    [ConvocatoriaDetalle] nvarchar(max)  NOT NULL,
    [ConvocatoriaQuorum] int  NOT NULL,
    [ConvocatoriaUbicacionX] nvarchar(max)  NOT NULL,
    [ConvocatoriaUbicacionY] nvarchar(max)  NOT NULL,
    [ConvocatoriaLogo] varbinary(max)  NOT NULL,
    [MovimientoId] int  NOT NULL,
    [CategoriaTematicaId] int  NOT NULL
);
GO

-- Creating table 'Filtros'
CREATE TABLE [dbo].[Filtros] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [FiltroNombre] nvarchar(max)  NOT NULL,
    [FiltroValor] nvarchar(max)  NOT NULL,
    [OrigenDeDatoId] int  NOT NULL,
    [MovimientoId] int  NOT NULL
);
GO

-- Creating table 'Movimientos'
CREATE TABLE [dbo].[Movimientos] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [MovimientoNombre] nvarchar(max)  NOT NULL,
    [MovimientoUbicacionX] nvarchar(max)  NOT NULL,
    [MovimientoUbicacionY] nvarchar(max)  NOT NULL,
    [MovimientoDescripcion] nvarchar(max)  NOT NULL,
    [MovimientoLogo] varbinary(max)  NOT NULL,
    [MovimientoEstiloCSS] varbinary(max)  NULL,
    [MovimientoConstM] int  NOT NULL,
    [MovimientoConstN] int  NOT NULL,
    [MovimientoConstX] int  NOT NULL,
    [MovimientoConstZ] int  NOT NULL,
    [MovimientoHost] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Notificaciones'
CREATE TABLE [dbo].[Notificaciones] (
    [FueVista] bit  NOT NULL,
    [ConvocatoriaId] int  NOT NULL,
    [UsuarioId] int  NOT NULL,
    [MovimientoId] int  NOT NULL
);
GO

-- Creating table 'OrigenDeDatos'
CREATE TABLE [dbo].[OrigenDeDatos] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [OrigenDeDatoTipo] nvarchar(max)  NOT NULL,
    [OrigenDeDatoUrl] nvarchar(max)  NULL,
    [OrigenDeDatoDLL] varbinary(max)  NULL,
    [OrigenDeDatoNombre] nvarchar(max)  NOT NULL,
    [MovimientoId] int  NOT NULL,
    [OrigenDeDatoData] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'UsuariosAdmin'
CREATE TABLE [dbo].[UsuariosAdmin] (
    [UsuarioAdminNombre] nvarchar(max)  NOT NULL,
    [UsuarioAdminPassword] nvarchar(max)  NOT NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'Usuarios'
CREATE TABLE [dbo].[Usuarios] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UsuarioNombre] nvarchar(max)  NOT NULL,
    [UsuarioMail] nvarchar(max)  NOT NULL,
    [UsuarioFechaRegistro] datetime  NOT NULL,
    [UsuarioUbicacionX] nvarchar(max)  NOT NULL,
    [UsuarioUbicacionY] nvarchar(max)  NOT NULL,
    [UsuarioDadoBaja] bit  NOT NULL,
    [UsuarioRedSocial] nvarchar(max)  NOT NULL,
    [UsuarioFacebook] bigint  NULL,
    [UsuarioTwitter] bigint  NULL,
    [UsuarioLogueado] bit  NULL,
    [MovimientoId] int  NOT NULL
);
GO

-- Creating table 'Galerias'
CREATE TABLE [dbo].[Galerias] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [GaleriaData] varbinary(max)  NOT NULL,
    [MovimientoId] int  NOT NULL,
    [GaleriaFormato] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Marcas'
CREATE TABLE [dbo].[Marcas] (
    [MovimientoId] int  NOT NULL,
    [UsuarioId] int  NOT NULL,
    [ContenidoId] int  NOT NULL
);
GO

-- Creating table 'Chat'
CREATE TABLE [dbo].[Chat] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [MovimientoId] int  NOT NULL,
    [UsuarioSolicitanteId] int  NOT NULL,
    [UsuarioReceptorId] int  NOT NULL,
    [SesionChatFechaCreada] datetime  NOT NULL,
    [SesionChatAceptada] bit  NOT NULL,
    [SesionChatCerrada] bit  NOT NULL
);
GO

-- Creating table 'Mensajes'
CREATE TABLE [dbo].[Mensajes] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [SesionChatId] int  NOT NULL,
    [MovimientoId] int  NOT NULL,
    [MensajeFechaEnvio] datetime  NOT NULL,
    [MensajeTexto] nvarchar(max)  NOT NULL,
    [MensajeEmisorNombre] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'CategoriasTematicas'
CREATE TABLE [dbo].[CategoriasTematicas] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [CategoriaTematicaNombre] nvarchar(max)  NOT NULL,
    [MovimientoId] int  NOT NULL
);
GO

-- Creating table 'Marcas_MeGusta'
CREATE TABLE [dbo].[Marcas_MeGusta] (
    [MeGustaFecha] datetime  NOT NULL,
    [UsuarioId] int  NOT NULL,
    [ContenidoId] int  NOT NULL
);
GO

-- Creating table 'Marcas_Inadecuado'
CREATE TABLE [dbo].[Marcas_Inadecuado] (
    [UsuarioId] int  NOT NULL,
    [ContenidoId] int  NOT NULL
);
GO

-- Creating table 'Contenidos_Video'
CREATE TABLE [dbo].[Contenidos_Video] (
    [VideoData] varbinary(max)  NOT NULL,
    [VideoFormato] nvarchar(max)  NOT NULL,
    [VideoWidth] nvarchar(max)  NULL,
    [VideoHeight] nvarchar(max)  NOT NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'Contenidos_Imagen'
CREATE TABLE [dbo].[Contenidos_Imagen] (
    [ImagenData] varbinary(max)  NOT NULL,
    [ImagenFormato] nvarchar(max)  NOT NULL,
    [ImagenWidth] nvarchar(max)  NOT NULL,
    [ImagenHeight] nvarchar(max)  NOT NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'Contenidos_Link'
CREATE TABLE [dbo].[Contenidos_Link] (
    [LinkUrl] nvarchar(max)  NOT NULL,
    [LinkComentario] nvarchar(max)  NOT NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'UsuarioConvocatoria'
CREATE TABLE [dbo].[UsuarioConvocatoria] (
    [Usuario_Id] int  NOT NULL,
    [Convocatoria_Id] int  NOT NULL
);
GO

-- Creating table 'CategoriaTematicaUsuario'
CREATE TABLE [dbo].[CategoriaTematicaUsuario] (
    [CategoriaTematica_Id] int  NOT NULL,
    [Usuario_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Contenidos'
ALTER TABLE [dbo].[Contenidos]
ADD CONSTRAINT [PK_Contenidos]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Convocatorias'
ALTER TABLE [dbo].[Convocatorias]
ADD CONSTRAINT [PK_Convocatorias]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Filtros'
ALTER TABLE [dbo].[Filtros]
ADD CONSTRAINT [PK_Filtros]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Movimientos'
ALTER TABLE [dbo].[Movimientos]
ADD CONSTRAINT [PK_Movimientos]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [ConvocatoriaId], [UsuarioId] in table 'Notificaciones'
ALTER TABLE [dbo].[Notificaciones]
ADD CONSTRAINT [PK_Notificaciones]
    PRIMARY KEY CLUSTERED ([ConvocatoriaId], [UsuarioId] ASC);
GO

-- Creating primary key on [Id] in table 'OrigenDeDatos'
ALTER TABLE [dbo].[OrigenDeDatos]
ADD CONSTRAINT [PK_OrigenDeDatos]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UsuariosAdmin'
ALTER TABLE [dbo].[UsuariosAdmin]
ADD CONSTRAINT [PK_UsuariosAdmin]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Usuarios'
ALTER TABLE [dbo].[Usuarios]
ADD CONSTRAINT [PK_Usuarios]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Galerias'
ALTER TABLE [dbo].[Galerias]
ADD CONSTRAINT [PK_Galerias]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [UsuarioId], [ContenidoId] in table 'Marcas'
ALTER TABLE [dbo].[Marcas]
ADD CONSTRAINT [PK_Marcas]
    PRIMARY KEY CLUSTERED ([UsuarioId], [ContenidoId] ASC);
GO

-- Creating primary key on [Id] in table 'Chat'
ALTER TABLE [dbo].[Chat]
ADD CONSTRAINT [PK_Chat]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Mensajes'
ALTER TABLE [dbo].[Mensajes]
ADD CONSTRAINT [PK_Mensajes]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CategoriasTematicas'
ALTER TABLE [dbo].[CategoriasTematicas]
ADD CONSTRAINT [PK_CategoriasTematicas]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [UsuarioId], [ContenidoId] in table 'Marcas_MeGusta'
ALTER TABLE [dbo].[Marcas_MeGusta]
ADD CONSTRAINT [PK_Marcas_MeGusta]
    PRIMARY KEY CLUSTERED ([UsuarioId], [ContenidoId] ASC);
GO

-- Creating primary key on [UsuarioId], [ContenidoId] in table 'Marcas_Inadecuado'
ALTER TABLE [dbo].[Marcas_Inadecuado]
ADD CONSTRAINT [PK_Marcas_Inadecuado]
    PRIMARY KEY CLUSTERED ([UsuarioId], [ContenidoId] ASC);
GO

-- Creating primary key on [Id] in table 'Contenidos_Video'
ALTER TABLE [dbo].[Contenidos_Video]
ADD CONSTRAINT [PK_Contenidos_Video]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Contenidos_Imagen'
ALTER TABLE [dbo].[Contenidos_Imagen]
ADD CONSTRAINT [PK_Contenidos_Imagen]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Contenidos_Link'
ALTER TABLE [dbo].[Contenidos_Link]
ADD CONSTRAINT [PK_Contenidos_Link]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Usuario_Id], [Convocatoria_Id] in table 'UsuarioConvocatoria'
ALTER TABLE [dbo].[UsuarioConvocatoria]
ADD CONSTRAINT [PK_UsuarioConvocatoria]
    PRIMARY KEY NONCLUSTERED ([Usuario_Id], [Convocatoria_Id] ASC);
GO

-- Creating primary key on [CategoriaTematica_Id], [Usuario_Id] in table 'CategoriaTematicaUsuario'
ALTER TABLE [dbo].[CategoriaTematicaUsuario]
ADD CONSTRAINT [PK_CategoriaTematicaUsuario]
    PRIMARY KEY NONCLUSTERED ([CategoriaTematica_Id], [Usuario_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [MovimientoId] in table 'Convocatorias'
ALTER TABLE [dbo].[Convocatorias]
ADD CONSTRAINT [FK_MovimientoConvocatoria]
    FOREIGN KEY ([MovimientoId])
    REFERENCES [dbo].[Movimientos]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MovimientoConvocatoria'
CREATE INDEX [IX_FK_MovimientoConvocatoria]
ON [dbo].[Convocatorias]
    ([MovimientoId]);
GO

-- Creating foreign key on [Usuario_Id] in table 'UsuarioConvocatoria'
ALTER TABLE [dbo].[UsuarioConvocatoria]
ADD CONSTRAINT [FK_UsuarioConvocatoria_Usuario]
    FOREIGN KEY ([Usuario_Id])
    REFERENCES [dbo].[Usuarios]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Convocatoria_Id] in table 'UsuarioConvocatoria'
ALTER TABLE [dbo].[UsuarioConvocatoria]
ADD CONSTRAINT [FK_UsuarioConvocatoria_Convocatoria]
    FOREIGN KEY ([Convocatoria_Id])
    REFERENCES [dbo].[Convocatorias]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioConvocatoria_Convocatoria'
CREATE INDEX [IX_FK_UsuarioConvocatoria_Convocatoria]
ON [dbo].[UsuarioConvocatoria]
    ([Convocatoria_Id]);
GO

-- Creating foreign key on [ConvocatoriaId] in table 'Notificaciones'
ALTER TABLE [dbo].[Notificaciones]
ADD CONSTRAINT [FK_NotificacionConvocatoria]
    FOREIGN KEY ([ConvocatoriaId])
    REFERENCES [dbo].[Convocatorias]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [UsuarioId] in table 'Notificaciones'
ALTER TABLE [dbo].[Notificaciones]
ADD CONSTRAINT [FK_NotificacionUsuario]
    FOREIGN KEY ([UsuarioId])
    REFERENCES [dbo].[Usuarios]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_NotificacionUsuario'
CREATE INDEX [IX_FK_NotificacionUsuario]
ON [dbo].[Notificaciones]
    ([UsuarioId]);
GO

-- Creating foreign key on [MovimientoId] in table 'Notificaciones'
ALTER TABLE [dbo].[Notificaciones]
ADD CONSTRAINT [FK_NotificacionMovimiento]
    FOREIGN KEY ([MovimientoId])
    REFERENCES [dbo].[Movimientos]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_NotificacionMovimiento'
CREATE INDEX [IX_FK_NotificacionMovimiento]
ON [dbo].[Notificaciones]
    ([MovimientoId]);
GO

-- Creating foreign key on [MovimientoId] in table 'Usuarios'
ALTER TABLE [dbo].[Usuarios]
ADD CONSTRAINT [FK_MovimientoUsuario]
    FOREIGN KEY ([MovimientoId])
    REFERENCES [dbo].[Movimientos]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MovimientoUsuario'
CREATE INDEX [IX_FK_MovimientoUsuario]
ON [dbo].[Usuarios]
    ([MovimientoId]);
GO

-- Creating foreign key on [UsuarioId] in table 'Contenidos'
ALTER TABLE [dbo].[Contenidos]
ADD CONSTRAINT [FK_UsuarioContenido]
    FOREIGN KEY ([UsuarioId])
    REFERENCES [dbo].[Usuarios]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioContenido'
CREATE INDEX [IX_FK_UsuarioContenido]
ON [dbo].[Contenidos]
    ([UsuarioId]);
GO

-- Creating foreign key on [MovimientoId] in table 'Contenidos'
ALTER TABLE [dbo].[Contenidos]
ADD CONSTRAINT [FK_ContenidoMovimiento]
    FOREIGN KEY ([MovimientoId])
    REFERENCES [dbo].[Movimientos]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ContenidoMovimiento'
CREATE INDEX [IX_FK_ContenidoMovimiento]
ON [dbo].[Contenidos]
    ([MovimientoId]);
GO

-- Creating foreign key on [MovimientoId] in table 'Marcas'
ALTER TABLE [dbo].[Marcas]
ADD CONSTRAINT [FK_MarcaMovimiento]
    FOREIGN KEY ([MovimientoId])
    REFERENCES [dbo].[Movimientos]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MarcaMovimiento'
CREATE INDEX [IX_FK_MarcaMovimiento]
ON [dbo].[Marcas]
    ([MovimientoId]);
GO

-- Creating foreign key on [UsuarioId] in table 'Marcas'
ALTER TABLE [dbo].[Marcas]
ADD CONSTRAINT [FK_MarcaUsuario]
    FOREIGN KEY ([UsuarioId])
    REFERENCES [dbo].[Usuarios]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [ContenidoId] in table 'Marcas'
ALTER TABLE [dbo].[Marcas]
ADD CONSTRAINT [FK_MarcaContenido]
    FOREIGN KEY ([ContenidoId])
    REFERENCES [dbo].[Contenidos]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MarcaContenido'
CREATE INDEX [IX_FK_MarcaContenido]
ON [dbo].[Marcas]
    ([ContenidoId]);
GO

-- Creating foreign key on [MovimientoId] in table 'OrigenDeDatos'
ALTER TABLE [dbo].[OrigenDeDatos]
ADD CONSTRAINT [FK_OrigenDeDatoMovimiento]
    FOREIGN KEY ([MovimientoId])
    REFERENCES [dbo].[Movimientos]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrigenDeDatoMovimiento'
CREATE INDEX [IX_FK_OrigenDeDatoMovimiento]
ON [dbo].[OrigenDeDatos]
    ([MovimientoId]);
GO

-- Creating foreign key on [OrigenDeDatoId] in table 'Filtros'
ALTER TABLE [dbo].[Filtros]
ADD CONSTRAINT [FK_OrigenDeDatoFiltro]
    FOREIGN KEY ([OrigenDeDatoId])
    REFERENCES [dbo].[OrigenDeDatos]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrigenDeDatoFiltro'
CREATE INDEX [IX_FK_OrigenDeDatoFiltro]
ON [dbo].[Filtros]
    ([OrigenDeDatoId]);
GO

-- Creating foreign key on [MovimientoId] in table 'Filtros'
ALTER TABLE [dbo].[Filtros]
ADD CONSTRAINT [FK_FiltroMovimiento]
    FOREIGN KEY ([MovimientoId])
    REFERENCES [dbo].[Movimientos]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FiltroMovimiento'
CREATE INDEX [IX_FK_FiltroMovimiento]
ON [dbo].[Filtros]
    ([MovimientoId]);
GO

-- Creating foreign key on [MovimientoId] in table 'Galerias'
ALTER TABLE [dbo].[Galerias]
ADD CONSTRAINT [FK_MovimientoGaleria]
    FOREIGN KEY ([MovimientoId])
    REFERENCES [dbo].[Movimientos]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MovimientoGaleria'
CREATE INDEX [IX_FK_MovimientoGaleria]
ON [dbo].[Galerias]
    ([MovimientoId]);
GO

-- Creating foreign key on [MovimientoId] in table 'Chat'
ALTER TABLE [dbo].[Chat]
ADD CONSTRAINT [FK_MovimientoChat]
    FOREIGN KEY ([MovimientoId])
    REFERENCES [dbo].[Movimientos]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MovimientoChat'
CREATE INDEX [IX_FK_MovimientoChat]
ON [dbo].[Chat]
    ([MovimientoId]);
GO

-- Creating foreign key on [SesionChatId] in table 'Mensajes'
ALTER TABLE [dbo].[Mensajes]
ADD CONSTRAINT [FK_SesionChatMensaje]
    FOREIGN KEY ([SesionChatId])
    REFERENCES [dbo].[Chat]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SesionChatMensaje'
CREATE INDEX [IX_FK_SesionChatMensaje]
ON [dbo].[Mensajes]
    ([SesionChatId]);
GO

-- Creating foreign key on [MovimientoId] in table 'Mensajes'
ALTER TABLE [dbo].[Mensajes]
ADD CONSTRAINT [FK_MovimientoMensaje]
    FOREIGN KEY ([MovimientoId])
    REFERENCES [dbo].[Movimientos]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MovimientoMensaje'
CREATE INDEX [IX_FK_MovimientoMensaje]
ON [dbo].[Mensajes]
    ([MovimientoId]);
GO

-- Creating foreign key on [UsuarioSolicitanteId] in table 'Chat'
ALTER TABLE [dbo].[Chat]
ADD CONSTRAINT [FK_UsuarioSesionChat]
    FOREIGN KEY ([UsuarioSolicitanteId])
    REFERENCES [dbo].[Usuarios]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioSesionChat'
CREATE INDEX [IX_FK_UsuarioSesionChat]
ON [dbo].[Chat]
    ([UsuarioSolicitanteId]);
GO

-- Creating foreign key on [UsuarioReceptorId] in table 'Chat'
ALTER TABLE [dbo].[Chat]
ADD CONSTRAINT [FK_UsuarioSesionChat1]
    FOREIGN KEY ([UsuarioReceptorId])
    REFERENCES [dbo].[Usuarios]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioSesionChat1'
CREATE INDEX [IX_FK_UsuarioSesionChat1]
ON [dbo].[Chat]
    ([UsuarioReceptorId]);
GO

-- Creating foreign key on [MovimientoId] in table 'CategoriasTematicas'
ALTER TABLE [dbo].[CategoriasTematicas]
ADD CONSTRAINT [FK_CategoriaTematicaMovimiento]
    FOREIGN KEY ([MovimientoId])
    REFERENCES [dbo].[Movimientos]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CategoriaTematicaMovimiento'
CREATE INDEX [IX_FK_CategoriaTematicaMovimiento]
ON [dbo].[CategoriasTematicas]
    ([MovimientoId]);
GO

-- Creating foreign key on [CategoriaTematica_Id] in table 'CategoriaTematicaUsuario'
ALTER TABLE [dbo].[CategoriaTematicaUsuario]
ADD CONSTRAINT [FK_CategoriaTematicaUsuario_CategoriaTematica]
    FOREIGN KEY ([CategoriaTematica_Id])
    REFERENCES [dbo].[CategoriasTematicas]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Usuario_Id] in table 'CategoriaTematicaUsuario'
ALTER TABLE [dbo].[CategoriaTematicaUsuario]
ADD CONSTRAINT [FK_CategoriaTematicaUsuario_Usuario]
    FOREIGN KEY ([Usuario_Id])
    REFERENCES [dbo].[Usuarios]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CategoriaTematicaUsuario_Usuario'
CREATE INDEX [IX_FK_CategoriaTematicaUsuario_Usuario]
ON [dbo].[CategoriaTematicaUsuario]
    ([Usuario_Id]);
GO

-- Creating foreign key on [CategoriaTematicaId] in table 'Convocatorias'
ALTER TABLE [dbo].[Convocatorias]
ADD CONSTRAINT [FK_CategoriaTematicaConvocatoria]
    FOREIGN KEY ([CategoriaTematicaId])
    REFERENCES [dbo].[CategoriasTematicas]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CategoriaTematicaConvocatoria'
CREATE INDEX [IX_FK_CategoriaTematicaConvocatoria]
ON [dbo].[Convocatorias]
    ([CategoriaTematicaId]);
GO

-- Creating foreign key on [UsuarioId], [ContenidoId] in table 'Marcas_MeGusta'
ALTER TABLE [dbo].[Marcas_MeGusta]
ADD CONSTRAINT [FK_MeGusta_inherits_Marca]
    FOREIGN KEY ([UsuarioId], [ContenidoId])
    REFERENCES [dbo].[Marcas]
        ([UsuarioId], [ContenidoId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [UsuarioId], [ContenidoId] in table 'Marcas_Inadecuado'
ALTER TABLE [dbo].[Marcas_Inadecuado]
ADD CONSTRAINT [FK_Inadecuado_inherits_Marca]
    FOREIGN KEY ([UsuarioId], [ContenidoId])
    REFERENCES [dbo].[Marcas]
        ([UsuarioId], [ContenidoId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Contenidos_Video'
ALTER TABLE [dbo].[Contenidos_Video]
ADD CONSTRAINT [FK_Video_inherits_Contenido]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Contenidos]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Contenidos_Imagen'
ALTER TABLE [dbo].[Contenidos_Imagen]
ADD CONSTRAINT [FK_Imagen_inherits_Contenido]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Contenidos]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Contenidos_Link'
ALTER TABLE [dbo].[Contenidos_Link]
ADD CONSTRAINT [FK_Link_inherits_Contenido]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Contenidos]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------